#pragma once
#include <string>
#include <list>
#include <map>
#include <wtypes.h>


namespace process_helper
{
	bool invoke_svn(std::string svn, std::string param, std::string &output);
};

class dir_scan_base
{
public:
	dir_scan_base(){}
	bool scan(std::string dir);
	void set_filter(std::list<std::string> &extList)
	{
		listExtentions = extList;
	}
protected:
	virtual void on_file_found(std::string filename) = 0;
private:
	void on_entry_found(std::string dir, WIN32_FIND_DATA &FindFileData);
	std::string find_file_ext(std::string filename);
	bool is_ext_in_list(std::string ext);
	std::list<std::string> listExtentions;
};

struct AUTHOR_LINE 
{
	std::string author;
	long lines;
};

class svn_stat : public dir_scan_base
{
public:
	svn_stat()
	{
		svn_execute = "svn.exe";
	}
	void set_svn_execute(std::string exe)
	{
		svn_execute = exe;
	}
	bool begin(std::string dir)
	{
		stat_dir = dir;
		printf("stat dir revisions...");
		if (!stat_dir_revisions()) return false;
		printf("ok\n");

		printf("scanning source dir...\n");
		if (!scan(stat_dir)) return false;
		printf("scanning source dir done.\n");
		return true;
	}
	std::string output();
protected:
	virtual void on_file_found(std::string filename);
private:
	std::map<long,long> mapRevisionDate;
	long find_revision_date(long rev)
	{
		std::map<long,long>::iterator i = mapRevisionDate.find(rev);
		if (i!= mapRevisionDate.end()) return (*i).second;
		return 0;
	}

	std::map<long,std::list<AUTHOR_LINE> > mapDateAuthorLines;

	std::string stat_dir;
	std::string svn_execute;

	bool stat_dir_revisions();
};